package com.ruoyi.web.controller.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.module.domain.FundDetails;
import com.ruoyi.module.service.IFundDetailsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.module.domain.Recharge;
import com.ruoyi.module.service.IRechargeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 在线充值Controller
 *
 * @author fubojin
 * @date 2025-01-10
 */
@RestController
@RequestMapping("/admin/recharge")
public class RechargeController extends BaseController {
    @Autowired
    private IRechargeService rechargeService;
    @Autowired
    private IFundDetailsService fundDetailsService;

    /**
     * 查询在线充值列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Recharge recharge) {
        startPage();
        List<Recharge> list = rechargeService.selectRechargeList(recharge);
        return getDataTable(list);
    }

    /**
     * 导出在线充值列表
     */
    @Log(title = "在线充值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Recharge recharge) {
        List<Recharge> list = rechargeService.selectRechargeList(recharge);
        ExcelUtil<Recharge> util = new ExcelUtil<Recharge>(Recharge.class);
        util.exportExcel(response, list, "在线充值数据");
    }

    /**
     * 获取在线充值详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rechargeService.selectRechargeById(id));
    }

    /**
     * 充值审核（通过）
     */
    @PostMapping(value = "approve/{id}")
    public AjaxResult approve(@PathVariable("id") Long id, @RequestParam boolean doublingSwitch, @RequestBody Recharge recharge) {

        return success(rechargeService.approve(id, doublingSwitch, recharge));
    }

    /**
     * 充值审核（拒绝）
     */
    @PostMapping(value = "reject/{id}")
    public AjaxResult reject(@PathVariable("id") Long id) {
        return success(rechargeService.reject(id));
    }

    /**
     * 新增在线充值
     */
    @Log(title = "在线充值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Recharge recharge) {
        return toAjax(rechargeService.insertRecharge(recharge));
    }

    /**
     * 修改在线充值
     */
    @Log(title = "在线充值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Recharge recharge) {
        return toAjax(rechargeService.updateRecharge(recharge));
    }

    /**
     * 删除在线充值
     */
    @Log(title = "在线充值", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rechargeService.deleteRechargeByIds(ids));
    }
}
